package com.wxx.搜索插入位置;

/**
 * @author: Jetwang
 * @date: 2022/3/29 21:52
 * @description: Solution
 * @version: 1.0
 */
public class Solution {
    public int searchInsert(int[] nums, int target) {
        int start = 0;
        int end = nums.length - 1;
        while (start <= end) {
            int middle = (start + end) / 2;
            if (nums[middle] == target) {
                return middle;
            } else if (nums[middle] > target) {
                end = middle - 1;
            } else if (nums[middle] < target){
                start = start + 1;
            }
        }
        return start;
    }

}
